package com.handmark.pulltorefresh.library.internal;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.bytedance.common.utility.Logger;
import com.handmark.pulltorefresh.library.ILoadingLayout;
import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode;
import com.handmark.pulltorefresh.library.PullToRefreshBase.Orientation;
import com.ss.android.article.browser.R;

@SuppressLint(value = {"ViewConstructor"})
public abstract class LoadingLayout extends FrameLayout implements ILoadingLayout {
    static final Interpolator a = new LinearInterpolator();

    public final ImageView c;
    public final TextView e;
    public final TextView f;
    public final View g;
    public final LinearLayout h;
    protected final ProgressBar d;
    protected final Mode j;
    protected final Orientation k;
    private final LinearLayout o;
    public ImageView b;
    public boolean i;
    public int l;
    private View m;
    private boolean n;
    private CharSequence p;
    private CharSequence q;
    private CharSequence r;

    public LoadingLayout(Context arg4, Mode arg5, Orientation arg6, TypedArray arg7) {
        super(arg4);
        ColorStateList v0_4;
        TypedValue v0_3;
        Drawable v0_2;
        int v1 = 8;
        this.j = arg5;
        this.k = arg6;
        LayoutInflater.from(arg4).inflate(this.a(arg6), ((ViewGroup) this));
        this.m = this.findViewById(com.ss.android.article.browser.R.id.fl_inner);
        this.e = this.m.findViewById(com.ss.android.article.browser.R.id.pull_to_refresh_text);
        this.d = this.m.findViewById(com.ss.android.article.browser.R.id.a83);
        this.f = this.m.findViewById(com.ss.android.article.browser.R.id.pull_to_refresh_sub_text);
        this.c = this.m.findViewById(com.ss.android.article.browser.R.id.pull_to_refresh_image);
        this.g = this.m.findViewById(com.ss.android.article.browser.R.id.home_page_header_layout);
        if (this.g != null) {
            this.g.setVisibility(GONE);
        }

        this.h = this.m.findViewById(com.ss.android.article.browser.R.id.extra_root);
        this.o = this.m.findViewById(com.ss.android.article.browser.R.id.extra);
        if (this.h != null) {
            LinearLayout v2 = this.h;
            int visibility = this.i ? VISIBLE : GONE;
            v2.setVisibility(visibility);
        }

        ViewGroup.LayoutParams v0_1 = this.m.getLayoutParams();
        switch (arg5) {
            case PULL_FROM_END: {
                v1 = arg6 == Orientation.VERTICAL ? 48 : 3;
                ((FrameLayout.LayoutParams) v0_1).gravity = v1;
                this.p = arg4.getString(com.ss.android.article.browser.R.string.pull_to_refresh_from_bottom_pull_label);
                this.q = arg4.getString(com.ss.android.article.browser.R.string.pull_to_refresh_from_bottom_refreshing_label);
                this.r = arg4.getString(com.ss.android.article.browser.R.string.pull_to_refresh_from_bottom_release_label);
                break;
            }
            default: {
                v1 = arg6 == Orientation.VERTICAL ? 80 : 5;
                ((FrameLayout.LayoutParams) v0_1).gravity = v1;
                this.p = arg4.getString(com.ss.android.article.browser.R.string.pull_to_refresh_pull_label);
                this.q = arg4.getString(com.ss.android.article.browser.R.string.pull_to_refresh_refreshing_label);
                this.r = arg4.getString(com.ss.android.article.browser.R.string.pull_to_refresh_release_label);
                break;
            }
        }

        if (arg7.hasValue(com.ss.android.common.dd.x)) {
            v0_2 = arg7.getDrawable(com.ss.android.common.dd.x);
            if (v0_2 != null) {
                if (Build.VERSION.SDK_INT >= 16) {
                    ((View) this).setBackground(v0_2);
                } else {
                    ((View) this).setBackgroundDrawable(v0_2);
                }
            }
        }

        if (arg7.hasValue(com.ss.android.common.dd.z)) {
            v0_3 = new TypedValue();
            arg7.getValue(com.ss.android.common.dd.z, v0_3);
            this.setTextAppearance(v0_3.data);
        }

        if (arg7.hasValue(com.ss.android.common.dd.H)) {
            v0_3 = new TypedValue();
            arg7.getValue(com.ss.android.common.dd.H, v0_3);
            this.setSubTextAppearance(v0_3.data);
        }

        if (arg7.hasValue(com.ss.android.common.dd.A)) {
            v0_4 = arg7.getColorStateList(com.ss.android.common.dd.A);
            if (v0_4 != null) {
                this.setTextColor(v0_4);
            }
        }

        if (arg7.hasValue(com.ss.android.common.dd.y)) {
            v0_4 = arg7.getColorStateList(com.ss.android.common.dd.y);
            if (v0_4 != null) {
                this.setSubTextColor(v0_4);
            }
        }

        v0_2 = null;
        if (arg7.hasValue(com.ss.android.common.dd.s)) {
            v0_2 = arg7.getDrawable(com.ss.android.common.dd.s);
        }

        switch (arg5) {
            case PULL_FROM_END: {
                if (arg7.hasValue(com.ss.android.common.dd.u)) {
                    v0_2 = arg7.getDrawable(com.ss.android.common.dd.u);
                } else if (arg7.hasValue(com.ss.android.common.dd.t)) {
                    android.support.design.a.warnDeprecation("ptrDrawableBottom", "ptrDrawableEnd");
                    v0_2 = arg7.getDrawable(com.ss.android.common.dd.t);
                }

                break;
            }
            default: {
                if (arg7.hasValue(com.ss.android.common.dd.v)) {
                    v0_2 = arg7.getDrawable(com.ss.android.common.dd.v);
                } else if (arg7.hasValue(com.ss.android.common.dd.w)) {
                    android.support.design.a.warnDeprecation("ptrDrawableTop", "ptrDrawableStart");
                    v0_2 = arg7.getDrawable(com.ss.android.common.dd.w);
                }

                break;
            }
        }

        if (v0_2 == null) {
            v0_2 = arg4.getResources().getDrawable(this.getDefaultDrawableResId());
        }

        this.setLoadingDrawable(v0_2);
        this.reset();
    }

    public void a(int arg2) {
        this.l |= arg2;
    }

    public int a(Orientation arg3) {
        switch (arg3) {
            case HORIZONTAL:
                return R.layout.hm;
            default:
                return R.layout.ho;
        }
    }

    public abstract void a();

    public abstract void a(float arg1);

    public abstract void a(Drawable arg1);

    public final void b(float arg2) {
        if (!this.n) {
            this.a(arg2);
        }
    }

    public abstract void b();

    public abstract void c();

    public abstract void d();

    public void e() {
        int v1 = 4;
        if (this.e.getVisibility() == VISIBLE) {
            this.e.setVisibility(INVISIBLE);
        }

        if (this.d != null && this.d.getVisibility() == VISIBLE) {
            this.d.setVisibility(INVISIBLE);
        }

        if (this.c.getVisibility() == VISIBLE) {
            this.c.setVisibility(INVISIBLE);
        }

        if (this.f.getVisibility() == VISIBLE) {
            this.f.setVisibility(INVISIBLE);
        }

        if (this.h != null && (this.i) && this.h.getVisibility() == VISIBLE) {
            this.h.setVisibility(INVISIBLE);
        }
    }

    public final void f() {
        if (this.e != null) {
            this.e.setText(this.p);
        }

        this.a();
    }

    public final void refreshing() {
        CharSequence v0_1 = "";
        if (this.e != null) {
            CharSequence v0 = this.q;
            if (v0 != null) {
                v0_1 = v0;
            }

            try {
                this.e.setText(v0_1);
            } catch (Exception v0_2) {
                Logger.throwExceptionInDebug(v0_2);
            }
        }

        if (this.n) {
            ((AnimationDrawable) this.c.getDrawable()).start();
        } else {
            this.b();
        }

        if (this.f != null) {
            this.f.setVisibility(GONE);
        }
    }

    public int getContentSize() {
        int v0;
        switch (k) {
            case HORIZONTAL: {
                v0 = this.m.getWidth();
                break;
            }
            default: {
                v0 = this.m.getHeight();
                break;
            }
        }

        return v0;
    }

    public abstract int getDefaultDrawableResId();

    public LinearLayout getExtraLayout() {
        return this.o;
    }

    public final int getPtrHeaderExtraSize() {
        int v0 = 0;
        if (this.h != null && this.h.getChildCount() > 0) {
            v0 = this.h.getHeight();
        }

        return v0;
    }

    public final void h() {
        if (this.e != null) {
            this.e.setText(this.r);
        }

        this.c();
    }

    public final void reset() {
        int v2 = 8;
        if (this.e != null) {
            this.e.setText(this.p);
        }

        this.c.setVisibility(VISIBLE);
        if (this.n) {
            ((AnimationDrawable)this.c.getDrawable()).stop();
        } else {
            this.d();
        }

        if (this.f != null) {
            if (TextUtils.isEmpty(this.f.getText())) {
                this.f.setVisibility(GONE);
            } else {
                this.f.setVisibility(VISIBLE);
            }
        }

        if (this.g != null) {
            this.g.setVisibility(GONE);
        }

        if (this.h != null) {
            LinearLayout v3 = this.h;
            int visibility = this.i ? VISIBLE : GONE;
            v3.setVisibility(visibility);
        }
    }

    public final void j() {
        if (this.e.getVisibility() != VISIBLE) {
            this.e.setVisibility(VISIBLE);
        }

        if (this.d != null && this.d.getVisibility() != VISIBLE) {
            this.d.setVisibility(VISIBLE);
        }

        if (this.c.getVisibility() != VISIBLE) {
            this.c.setVisibility(VISIBLE);
        }

        if (this.f.getVisibility() != VISIBLE) {
            this.f.setVisibility(VISIBLE);
        }
    }

    public void setExtraEnabled(boolean arg3) {
        this.i = arg3;
        if (this.h != null) {
            LinearLayout v1 = this.h;
            int v0 = this.i ? VISIBLE : GONE;
            v1.setVisibility(v0);
        }
    }

    public final void setHeight(int arg2) {
        this.getLayoutParams().height = arg2;
        this.requestLayout();
    }

    public void setLastUpdatedLabel(CharSequence lastUpdatedLabel) {
        this.setSubHeaderText(lastUpdatedLabel);
    }

    public void setLoadingDrawable(Drawable loadingDrawable) {
        this.c.setImageDrawable(loadingDrawable);
        this.n = loadingDrawable instanceof AnimationDrawable;
        this.a(loadingDrawable);
    }

    public final void setProgressDrawable(Drawable progressDrawable) {
        if (this.d != null) {
            this.d.setIndeterminateDrawable(progressDrawable);
            if (this.d.getWidth() > 0) {
                progressDrawable.setBounds(0, 0, this.d.getWidth(), this.d.getHeight());
            }
        }
    }

    public void setPullLabel(CharSequence pullLabel) {
        this.p = pullLabel;
    }

    public void setRefreshingLabel(CharSequence refreshingLabel) {
        this.q = refreshingLabel;
    }

    public void setReleaseLabel(CharSequence releaseLabel) {
        this.r = releaseLabel;
    }

    private void setSubHeaderText(CharSequence arg3) {
        int v1 = 8;
        if (this.f != null) {
            if (TextUtils.isEmpty(arg3)) {
                this.f.setVisibility(GONE);
            } else {
                this.f.setText(arg3);
                if (GONE == this.f.getVisibility()) {
                    this.f.setVisibility(VISIBLE);
                }
            }
        }
    }

    private void setSubTextAppearance(int arg3) {
        if (this.f != null) {
            this.f.setTextAppearance(this.getContext(), arg3);
        }
    }

    private void setSubTextColor(ColorStateList arg2) {
        if (this.f != null) {
            this.f.setTextColor(arg2);
        }
    }

    public void setSubTextColor(int arg2) {
        if (this.f != null) {
            this.f.setTextColor(arg2);
        }
    }

    public void setSubTypeface(Typeface arg2) {
        if (this.f != null) {
            this.f.setTypeface(arg2);
        }
    }

    private void setTextAppearance(int arg3) {
        if (this.e != null) {
            this.e.setTextAppearance(this.getContext(), arg3);
        }

        if (this.f != null) {
            this.f.setTextAppearance(this.getContext(), arg3);
        }
    }

    private void setTextColor(ColorStateList arg2) {
        if (this.e != null) {
            this.e.setTextColor(arg2);
        }

        if (this.f != null) {
            this.f.setTextColor(arg2);
        }
    }

    public void setTextColor(int colorId) {
        if (this.e != null) {
            this.e.setTextColor(colorId);
        }
    }

    public void setTextTypeface(Typeface arg2) {
        this.e.setTypeface(arg2);
    }

    public void setTheme(boolean isNightMode) {
    }

    public final void setWidth(int arg2) {
        this.getLayoutParams().width = arg2;
        this.requestLayout();
    }
}

